// pages/order/order.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {    
    //图标
    iconPath: app.globalData.iconPath,
    //轮播图
    advertImgPath: app.globalData.advertImgPath,
    //访问java后台
    goJavaBackstagePath: app.globalData.goJavaBackstagePath,
    //测试数据图片
    testDataImgPath: app.globalData.testDataImgPath,

    advertImgList:[],//轮播图列表
    carouselParam: {indicatorDots: false,autoplay: true,interval: 4000,duration: 1000,},//轮播参数
    num:'1',//默认选择查看未完成订单
    sellersUnfinishedOrderList:[],
    sellersFinishedOrderList:[],
    photoGrapherUnfinishedOrderList: [],
    photoGrapherfinishedOrderList: [],
    iconList:{},
    sellerId:null,
  },

  //选择未完成订单   完成订单
  chooseClickByStatu(event){
    
    if (event.target.dataset.num==1){
      this.setData({
        num: event.target.dataset.num,
      });
      if (this.data.sellersUnfinishedOrderList.length > 0) {
        this.setData({
          sellerId: this.data.sellersUnfinishedOrderList[0].id
        });
      } else if (this.data.photoGrapherUnfinishedOrderList.length > 0) {
        this.setData({
          sellerId: this.data.photoGrapherUnfinishedOrderList[0].id
        });
      } else {
        sellerId: null;
      }
    } else if (event.target.dataset.num == 2){
      this.setData({
        num: event.target.dataset.num,
      });
      if (this.data.sellersFinishedOrderList.length > 0) {
        this.setData({
          sellerId: this.data.sellersFinishedOrderList[0].id
        });
      } else if (this.data.photoGrapherfinishedOrderList.length > 0) {
        this.setData({
          sellerId: this.data.photoGrapherfinishedOrderList[0].id
        });
      } else {
        sellerId: null;
      }          
    }     
  }, 
  //点击打开店铺，展开订单
  clickOpenUnfinishedOder(event){
    if (this.data.sellerId == event.target.dataset.index){     
      this.setData({
        sellerId: null,
      });
    }else{
      this.setData({
        sellerId: event.target.dataset.index,
      });
    } 
  },

  nullClick(event){},
  //点击订单详情，进入产品列表页面-------------
  goProductList(event){
    var orderId = event.target.dataset.orderid;
    var orderStatus = event.target.dataset.orderstatus;
    wx.redirectTo({
      url: '../product/product?orderId=' + orderId + '&orderStatus='+orderStatus, 
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //从后台获取顶部轮播图列表、商家订单数据集合
    // wx.request({
    //   url: this.data.goJavaBackstagePath+'/order/getWXUserOrderInfo',
    //   data:{},
    //   header: {
    //     'content-type': 'application/json'
    //   },
    //   success: function (res) {
    //     console.log(res.data)
    //   }
    // })

    var that = this;
    
    //订单状态：1：初始化订单；2：可选照片上传完成；3：照片选择完成；4：支付完成；5：成果照片上传完成；6：验片完成
    var data={
      //轮播图
      advertImgList: [this.data.advertImgPath +'/swiper.png',
                      this.data.advertImgPath +'/swiper.png',
                      this.data.advertImgPath +'/swiper.png',
                      this.data.advertImgPath +'/swiper.png'],
      //图标
      iconList: { "jenter": this.data.iconPath + '/enter.png', 'jdown': this.data.iconPath +'/down.png'},
      //未完成 店铺
      sellersUnfinishedOrderList: [
      {
          'id': 1, 'name': "亚里士多德婚纱摄影", 'sellerheadportrait': this.data.iconPath+'/sellerportrait.png', orderList: [
          { "id": 1, 'sellerId':1, "name": '2017-8-8 订单', "amountMoney": 5000,'total':8000,"createTime":'2015-11-11', 'advanceCharge': 2000, 'status': 0, },
          { "id": 2, 'sellerId': 1, 'name': '2016-7-16 订单', "amountMoney": 3200, 'total': 8000, "createTime": '2015-11-11', 'advanceCharge': 600, 'status': 1, },
          { "id": 3, 'sellerId': 1, 'name': '2016-7-16 订单', "amountMoney": 12000, 'total': 20000, "createTime": '2015-11-11', 'advanceCharge': 3000, 'status': 2, }]
      },
      {
        'id': 2, 'name': "蒙拉丽莎婚纱摄影", 'sellerheadportrait': this.data.iconPath +'/sellerportrait.png', orderList: [
          { "id": 1, 'sellerId': 2, "name": '2017-8-8 订单', "amountMoney": 5000, 'total': 8000, "createTime": '2015-11-11', 'advanceCharge': 2000, 'status': 3, },
          { "id": 2, 'sellerId': 2, 'name': '2016-7-16 订单', "amountMoney": 3200, 'total': 8000, "createTime": '2015-11-11', 'advanceCharge': 600, 'status': 4, },
          { "id": 3, 'sellerId': 2, 'name': '2016-7-16 订单', "amountMoney": 12000, 'total': 20000, "createTime": '2015-11-11', 'advanceCharge': 3000, 'status': 5, }]
      },
      {
        'id': 3, 'name': "阿基米德私人订制高档摄影", 'sellerheadportrait': this.data.iconPath +'/sellerportrait.png', orderList: [
          { "id": 1, 'sellerId': 3, "name": '2017-8-8 订单', "amountMoney": 5000, 'total': 8000, "createTime": '2015-11-11', 'advanceCharge': 2000, 'status': 6, },
          { "id": 2, 'sellerId': 3, 'name': '2016-7-16 订单', "amountMoney": 3200, 'total': 8000, "createTime": '2015-11-11', 'advanceCharge': 600, 'status': 3, },
          { "id": 3, 'sellerId': 3, 'name': '2016-7-16 订单', "amountMoney": 12000, 'total': 20000, "createTime": '2015-11-11', 'advanceCharge': 3000, 'status': 1, }]
      }
      ],
      //已完成 店铺
      sellersFinishedOrderList: [
      {
          'id': 1, 'name': "亚里士多德婚纱摄影", 'sellerheadportrait': this.data.iconPath +'/sellerportrait.png', orderList: [
          { "id": 14, 'sellerId': 1, 'name': '2016-7-16 订单', "amountMoney": 12000, 'total': 20000, "createTime": '2015-11-11', 'advanceCharge': 3000, 'status': 6, },
          { "id": 13, 'sellerId': 1, 'name': '2016-7-16 订单', "amountMoney": 12000, 'total': 20000, "createTime": '2015-11-11', 'advanceCharge': 3000, 'status': 6, }]
      },
      {
        'id': 2, 'name': "蒙拉丽莎婚纱摄影", 'sellerheadportrait': this.data.iconPath +'/sellerportrait.png', orderList: [
         
          { "id": 12, 'sellerId': 2, 'name': '2016-7-16 订单', "amountMoney": 12000, 'total': 20000, "createTime": '2015-11-11', 'advanceCharge': 3000, 'status': 6, }]
      },
      {
        'id': 3, 'name': "阿基米德私人订制高档摄影", 'sellerheadportrait': this.data.iconPath +'/sellerportrait.png', orderList: [
         
          { "id": 11, 'sellerId': 3, 'name': '2016-7-16 订单', "amountMoney": 12000, 'total': 20000, "createTime": '2015-11-11', 'advanceCharge': 3000, 'status': 6, }]
      }
      ],
      //未完成  摄影师
      photoGrapherUnfinishedOrderList:[
        {
          'id': 14, 'name': "梵高个人摄影", 'userheadportrait': this.data.iconPath +'/sellerportrait.png', orderList: [
            { "id": 22, 'photoGrapherId': 14, 'name': '2016-7-16 订单', "amountMoney": 12000, 'total': 20000, "createTime": '2015-11-11', 'advanceCharge': 3000, 'status': 3, },
            { "id": 23, 'photoGrapherId': 14, 'name': '2016-7-16 订单', "amountMoney": 12000, 'total': 20000, "createTime": '2015-11-11', 'advanceCharge': 3000, 'status': 4, }]
        },
      ],
      //已完成 摄影师
      photoGrapherfinishedOrderList:[
        {
          'id': 52, 'name': "恒河个人摄影", 'userheadportrait': this.data.iconPath +'/sellerportrait.png', orderList: [
            { "id": 24, 'photoGrapherId': 52, "name": '2017-8-8 订单', "amountMoney": 5000, 'total': 20000, "createTime": '2015-11-11', 'advanceCharge': 2000, 'status': 6, },
           ]
        }
      ]
    }

    this.setData({
      advertImgList:data.advertImgList,
      iconList: data.iconList,
      sellersUnfinishedOrderList: data.sellersUnfinishedOrderList,
      sellersFinishedOrderList: data.sellersFinishedOrderList,
      photoGrapherfinishedOrderList: data.photoGrapherfinishedOrderList,
      photoGrapherUnfinishedOrderList: data.photoGrapherUnfinishedOrderList,
      
    })
    if (data.sellersUnfinishedOrderList.length>0){
      this.setData({
        sellerId: data.sellersUnfinishedOrderList[0].id
      });
    } else if (data.photoGrapherUnfinishedOrderList.length > 0){
      this.setData({
        sellerId: data.photoGrapherUnfinishedOrderList[0].id
      });
    }else{
      sellerId:null;
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})